/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DesktopArea.java
 *
 * Created on 06/05/2011, 11:23:26
 */

package Interface;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JDesktopPane;

/**
 *
 * @author fagner
 */
public class DesktopArea extends JDesktopPane {

    private Image img;

    /** Creates new form DesktopArea */
    public DesktopArea() {
            try {
                img = javax.imageio.ImageIO.read(new java.net.URL(getClass().getResource("background.png"), "background.png"));
            } catch (Exception ex) {}
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
    }// </editor-fold>//GEN-END:initComponents

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            if (img != null) {
                Dimension dimension = this.getSize();
                int x = (int)(dimension.getWidth() - img.getWidth(this)) / 2;
                int y = (int)(dimension.getHeight() - img.getHeight(this)) / 2;

                g.drawImage(img, x, y, img.getWidth(this), img.getHeight(this), this);
            } else {
                g.drawString("Imagem nao encontrada", 50, 50);
            }
        }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

}
